package com.wangcang.widgetlibrary.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.wangcang.widgetlibrary.R;
import com.wangcang.widgetlibrary.bean.SelectBean;

import java.util.List;

/**
 * @author : mundane
 * @time : 2017/7/11 15:06
 * @description :
 * @file : SingleSelectedAdapter.java
 */

public class MultiSelectedAdapter extends BaseAdapter {

	private List<SelectBean> mList;

	public MultiSelectedAdapter(List<SelectBean> list) {
		mList = list;
	}

	@Override
	public int getCount() {
		return mList.size();
	}

	@Override
	public Object getItem(int position) {
		return mList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_multi_select, parent, false);
			holder = new ViewHolder(convertView);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		SelectBean bean = mList.get(position);
		holder.tv.setText(bean.text);
		if (bean.isSelected) {
			holder.iv.setVisibility(View.VISIBLE);
			holder.tv.setTextColor(parent.getResources().getColor(R.color.common_color_c1_337cff));
		} else {
			holder.iv.setVisibility(View.INVISIBLE);
			holder.tv.setTextColor(parent.getResources().getColor(R.color.common_color_c5_45494e));
		}


		return convertView;
	}

	static class ViewHolder {
		TextView tv;
		ImageView iv;
		public ViewHolder(View view) {
			tv = (TextView) view.findViewById(R.id.tv);
			iv = (ImageView) view.findViewById(R.id.iv);
		}
	}
}
